package Controller.Employee;

import Service.EmployeeService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;

/*
* 删除员工
* */
@WebServlet(name = "deleteEmployee", value = "/DeleteEmployee")
public class DeleteEmployee extends HttpServlet {
    private EmployeeService employeeService = new EmployeeService();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //通过id来删除员工
        Integer id = Integer.parseInt(request.getParameter("id"));
        try{
            employeeService.deleteEmployee(id);
            //请求转发到分页列表页面
            request.getRequestDispatcher("/ListEmployee").forward(request,response);
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
